/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TUFormRekapData.java
 *
 * Created on Nov 9, 2012, 2:44:36 PM
 */
package Form;

import Boundary.TU;
import Control.TUkontrol;
import Table.TUDataSiswaTabelModel;
import Table.TUPresensiTabelModel;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;


/**
 *
 * @author Fave
 */
public class TUFormRekapData extends javax.swing.JFrame {

    /**
     * Creates new form TUFormRekapData
     */
    public TUFormRekapData() {
//        jInternalFrame1.setEnabled(false);
        setTitle("Sistem Presensi Akademik SMS Gateway");
        setResizable(false);
        initComponents();
        GregorianCalendar gc = new GregorianCalendar();
        tanggal.setDate(gc.getTime());
        Date tgl = this.tanggal.getDate();
        SimpleDateFormat tglsimple = new SimpleDateFormat("dd-MM-yyyy");
        String tanggal = tglsimple.format(tgl);
        String kelas = ComboKelas.getSelectedItem().toString();
        try {
            List<TU> tu = (List<TU>) TUkontrol.getKoneksi().getAllpresensi(tanggal, kelas);
            TUPresensiTabelModel model = new TUPresensiTabelModel(tu);
            TabelRekapData.setModel(model);
        } catch (Exception e) {
            Logger.getLogger(TUFormDataSiswa.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TabelRekapData = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ComboKelas = new javax.swing.JComboBox();
        EditButton = new javax.swing.JToggleButton();
        tanggal = new com.toedter.calendar.JDateChooser();
        LihatPresensiButton = new javax.swing.JButton();
        closebutton = new javax.swing.JButton();
        cetakbutt = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/banner1.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Rekap Data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        TabelRekapData.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "NIS", "Nama", "Kelas", "Masuk", "Ijin", "Sakit", "Tidak Hadir"
            }
        ));
        jScrollPane1.setViewportView(TabelRekapData);

        jLabel2.setText("Tanggal");

        jLabel3.setText("Kelas");

        ComboKelas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3" }));
        ComboKelas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboKelasActionPerformed(evt);
            }
        });

        EditButton.setText("Edit");
        EditButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditButtonActionPerformed(evt);
            }
        });

        LihatPresensiButton.setText("Lihat Presensi");
        LihatPresensiButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LihatPresensiButtonActionPerformed(evt);
            }
        });

        closebutton.setText("Keluar");
        closebutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closebuttonActionPerformed(evt);
            }
        });

        cetakbutt.setText("Cetak");
        cetakbutt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cetakbuttActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(tanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(ComboKelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 341, Short.MAX_VALUE)
                        .addComponent(LihatPresensiButton)
                        .addGap(89, 89, 89))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(cetakbutt)
                        .addGap(18, 18, 18)
                        .addComponent(EditButton)
                        .addGap(18, 18, 18)
                        .addComponent(closebutton)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(ComboKelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(LihatPresensiButton))
                    .addComponent(tanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(closebutton)
                    .addComponent(EditButton)
                    .addComponent(cetakbutt)))
        );

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 140, 800, 370));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ComboKelasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboKelasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ComboKelasActionPerformed

    private void EditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditButtonActionPerformed
        EditDataPresensi e = new EditDataPresensi(this, true);
        e.setVisible(true);
    }//GEN-LAST:event_EditButtonActionPerformed

    private void LihatPresensiButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LihatPresensiButtonActionPerformed
        // TODO add your handling code here:
        Date tgl = this.tanggal.getDate();
        SimpleDateFormat tglsimple = new SimpleDateFormat("dd-MM-yyyy");
        String tanggal2 = tglsimple.format(tgl);
        String kelas = ComboKelas.getSelectedItem().toString();
        try {
            List<TU> tu = (List<TU>) TUkontrol.getKoneksi().getAllpresensi(tanggal2, kelas);
            TUPresensiTabelModel model = new TUPresensiTabelModel(tu);
            TabelRekapData.setModel(model);
        } catch (Exception e) {
            Logger.getLogger(TUFormDataSiswa.class.getName()).log(Level.SEVERE, null, e);
        }
    }//GEN-LAST:event_LihatPresensiButtonActionPerformed

    private void closebuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closebuttonActionPerformed
        // TODO add your handling code here:
        TUForm tf = new TUForm();
        tf.setVisible(true);
        dispose();
    }//GEN-LAST:event_closebuttonActionPerformed

    private void cetakbuttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cetakbuttActionPerformed
        try {
            Connection kon = null;
            String reportSource = "";
            kon = Tools.DataBaseConnection.KoneksiDataBase();
            //   Date tglawal = this.tanggalawal.getDate();

            String kelas = ComboKelas.getSelectedItem().toString();
            reportSource = "./report/cetak_rekap.jasper";

            Map<String, Object> params = new HashMap <String, Object>();
            try {
                params.put("kls", kelas);
                JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, params, kon);
                JasperViewer.viewReport(jasperPrint, false);

            } catch (JRException ex) {
                ex.printStackTrace();

            }

            this.setExtendedState(JFrame.ICONIFIED);



        } catch (SQLException ex) {
            Logger.getLogger(TUFormRekapData.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cetakbuttActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TUFormRekapData().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ComboKelas;
    private javax.swing.JToggleButton EditButton;
    private javax.swing.JButton LihatPresensiButton;
    private javax.swing.JTable TabelRekapData;
    private javax.swing.JButton cetakbutt;
    private javax.swing.JButton closebutton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private com.toedter.calendar.JDateChooser tanggal;
    // End of variables declaration//GEN-END:variables
}
